
#include "DeviceInfo.h"

using namespace ttg;
using namespace ttg::services;
using namespace ttg::extras::serialization;

//---------------------
//--- SubDeviceInfo ---
//---------------------

void SubDeviceInfo::serialize(Serializer &serializer)
{
	serializer.serializeString(getName(), "name");
	serializer.serializeString(unit_name, "unit_name");
	serializer.serializeFloat(usage, "usage");
	serializer.serializeFloat(max_value, "max_value");
}

void SubDeviceInfo::deserialize(DeSerializer &deserializer)
{
	std::string name;
	deserializer.deserializeString(name, "name");
	this->setName(name.c_str());
	deserializer.deserializeString(unit_name, "unit_name");
	deserializer.deserializeFloat(usage, "usage");
	deserializer.deserializeFloat(max_value, "max_value");
}

//------------------
//--- DeviceInfo ---
//------------------

void DeviceInfo::serialize(extras::serialization::Serializer &serializer)
{
	serializer.serializeString(getName(), "name");
	serializer.serializeString(unit_name, "unit_name");
	serializer.serializeString(description, "description");
	serializer.serializeFloat(usage, "usage");
	serializer.serializeFloat(max_value, "max_value");
	serializer.serializeInt((int)subdevices.size(), "subdevices_size");
	for (size_t i = 0; i < subdevices.size(); i++)
		serializer.serializeObject(subdevices[i], "subdevice");
}

void DeviceInfo::deserialize(extras::serialization::DeSerializer &deserializer)
{
	std::string name;
	deserializer.deserializeString(name, "name");
	this->setName(name.c_str());
	deserializer.deserializeString(unit_name, "unit_name");
	deserializer.deserializeString(description, "description");
	deserializer.deserializeFloat(usage, "usage");
	deserializer.deserializeFloat(max_value, "max_value");
	int size;
	deserializer.deserializeInt(size, "subdevices_size");
	subdevices.resize(size);
	for (int i = 0; i < size; i++)
	{
		subdevices[i] = new SubDeviceInfo();
		deserializer.deserializeObject(subdevices[i], "subdevice");
	}
}
